package com.cll.learn.stage10.example1;

import java.util.*;

/**
 * 描述信息:
 * 检测数组中元素是否唯一
 * @author CLL
 * @version 1.0
 * @date 2021/5/12 18:02
 */
public class CheckUnique {

    public static void main(String[] args) {
        int[] arr = new int[]{2,4,6,8,6,12};
        String result = checkArrayUnique(arr);
        System.out.println("result = " + result);
    }

    private static String checkArrayUnique(int[] array){
        Set<Integer> arrSet = new HashSet<>();
        for (int j : array) {
            if (arrSet.contains(j)) {
                return "NO";
            }
            arrSet.add(j);
        }
        return arrSet.size() == array.length ? "YES" : "NO";
    }
}